import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import BaseLittleThingsEntity from 'src/entities/base-little-things.entity';
import { Like, Repository } from 'typeorm';
import { LittleThingInfo } from './little-thing.dto';

@Injectable()
export class LittleThingService {
  constructor(
    @InjectRepository(BaseLittleThingsEntity)
    private readonly littleThingsRepository: Repository<BaseLittleThingsEntity>,
  ){}
  /**
   * 获取恋爱清单列表
   * @param ThingName 
   * @param Page 
   * @param PageSize 
   * @returns 
   */
  async getLittleThing(ThingName:string,Page:number,PageSize:number):Promise<{
    code:number,
    data:{
      total:number,
      list:LittleThingInfo[]
    }
  }>{
    // let where={}
    // if(ThingName!==''){
    //   where.
    // }
    const list=await this.littleThingsRepository.find({
      where:{
        ...(ThingName && { ThingName: Like(`%${ThingName}%`) })
      },
      skip:(Page-1)*PageSize,
      take:PageSize,
      order:{
        SysID:'ASC'
      }
    })
    const count=await this.littleThingsRepository.count({
      where:{
        ...(ThingName && { ThingName: Like(`%${ThingName}%`) })
      },
    })
    return {
      code:0,
      data:{
        total:count,
        list:list
      }
    }
  }
}
